'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ManageRepayidCtrl
 * @description
 * # ManageRepayidCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ManageRepayidCtrl', function($scope, openApi, Util, $location, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
        var selectLists = [];
        var relModuleObj = {}
        $scope.choosePeople = function() {
            relModuleObj = {
                name: "ManageLendidCtrl",
                selectTab: "deposit_select_project",
                selectTabContent: "投标申请单"
            };
            Util.savaParamForReview($scope.param, id);
            Util.savaDataforsearch(relModuleObj);

            $location.path("finance/choosepeople")
        };
        //获取证件信息列表
        $scope.getChoosecertId = function() {
            Util.saveSelectLists($scope.param.certificates);
            Util.savaParamForReview($scope.param, id);
            $location.path("manage/chooseinfo/hzj");
        };
        // 删除证件信息列表
        $scope.deletedItem = function(index) {
            $scope.param.certificates.splice(index, 1);
            $scope.index = -1;
            Util.saveSelectLists($scope.param.certificates);
        };
        var getAllcerIds = function() {
            var cerIds = [],
                cerIdsStr;
            $scope.param.certificates.forEach(function(item, index) {
                cerIds.push(item.cerId);
            });
            cerIdsStr = cerIds.join(",");
            return cerIdsStr;
        }
        $scope.swipe = function(index) {
            $scope.index = index;
        }
        $scope.resetlist = function(index) {
            $scope.index = -1;
        }
        $scope.submit = function(operationId) {

            $scope.param.cerIds = getAllcerIds();
            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.certificateReturn;
            options.param = angular.copy($scope.param, {});
            delete options.param.certificates
            delete options.param.formBidApply
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function() {
            if ($scope.param.certificates.length < 1) {
                Util.Toast("请选择证件信息");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData(id, function(data) {
                $scope.param = data;
                // 获取选择页面返回的数据并且合并到参数中
                selectLists = Util.getSelectLists();
                // 获取选择页面返回的数据并且合并到参数中
                $scope.param.certificates = selectLists || $scope.param.certificates || [];

            });
        };
        // 初始化
        init();
    });
